package view;

import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;

/**
 * The Class PackageReportGUI that extends AbstractGUI.
 * @author yudku
 */
public class PackageReportGUI  extends AbstractGUI
{
	
	/** The content pane. */
	private JPanel contentPane=null;
	
	/** The wrn message. */
	private JLabel wrnMessage=null;
	
	/** The Pack report. */
	private JTextArea PackReport = null;
	
	/** The send. */
	private JButton send = null;
	
	/**
	 * Instantiates a new package report gui.
	 */
	public PackageReportGUI()
	{
		super();
		contentPane=new JPanel();
	    contentPane.setBorder(new TitledBorder(null, "Package Report", TitledBorder.LEADING, TitledBorder.TOP, null, null));	    
	    contentPane.setLayout(null);
	    contentPane.setOpaque(true);
	    contentPane.add(getBackButton());	
		contentPane.add(getWrnMessage());
		contentPane.add(getPackReport());
		  //Frame
	        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
	        this.setTitle("Produce package report window");
	        this.setContentPane(contentPane);  
	        	        
	        JLabel label1_1 = new JLabel("Package Usage:");
	        label1_1.setBounds(20, 20, 190, 25);
	        contentPane.add(label1_1);
	        	        	        	        
	        send = new JButton("Send Report");
	        send.setBounds(120, 500, 121, 23);
	        contentPane.add(send);
	        	        
		    this.setLocationRelativeTo(null); //This will center the JFrame in the middle of the screen
	        this.setLocationByPlatform(true);
	        this.setSize(593, 600);
	        this.setVisible( true ); // display frame
	        this.setContentPane(contentPane);
	
	}
	
	/**
	 * This method initializes Back Button.
	 *
	 * @return the back button
	 */
	private JButton getBackButton() {
		if (backButton == null) {
			backButton = new JButton();
			backButton.setBounds(new Rectangle(339, 500, 121, 23));
			backButton.setText("Back");
			
		}
		return backButton;
	}
	
	 
	/**
	 * Sets the gen label.
	 *
	 * @param text the text
	 * @param label the label
	 */
	public void SetGenLabel(String text,JLabel label) {
		if (label != null) {

			label.setText(text);
		}
	}
	
	/**
	 * Gets the pack report.
	 *
	 * @return the pack report
	 */
	private JTextArea getPackReport() {
		if (PackReport == null) {
			PackReport = new JTextArea();
			PackReport.setBounds(new Rectangle(40, 50, 450, 400));
			PackReport.setBorder(BorderFactory.createLineBorder(Color.BLACK));
			
		}
		return PackReport;
	}
	
	/**
	 * Sets the pack report.
	 *
	 * @param msg the new pack report
	 */
	public void setPackReport(String msg){
		PackReport.setText(msg);
		PackReport.setVisible(true);
	}
	
	/**
	 * Display wrn message.
	 *
	 * @param msg the msg
	 */
	public void displayWrnMessage(String msg){
		wrnMessage.setText(msg);
		wrnMessage.setVisible(true);
	}
	
	/**
	 * Gets the wrn message.
	 *
	 * @return the wrn message
	 */
	private JLabel getWrnMessage() {
		if (wrnMessage == null) {
			wrnMessage = new JLabel();
			wrnMessage.setForeground(Color.RED);
			wrnMessage.setBounds(70, 16, 320, 23);
			wrnMessage.setVisible(false);
		}
		return wrnMessage;
	}
	
	/**
	 * Adds the reply action listener.
	 *
	 * @param listener the listener
	 */
	public void addReplyActionListener(ActionListener listener){
		send.addActionListener(listener);
	}
	
	/**
	 * Click back button.
	 */
	public void clickBackButton()
	{
		this.getBackButton().doClick();
	}
	
}